package com.kingschan.jeasytag.core.parse;
import javax.servlet.jsp.PageContext;
import org.apache.log4j.Logger;
import com.kingschan.jeasytag.core.annotations.tag.*;
import com.kingschan.jeasytag.core.format.JeasyTagFormat;
import com.kingschan.jeasytag.tag.RootTag;
import com.kingschan.util.lang.DateUtil;

/**
 * TagParseFactory
 * 2013-7-7
 * @author kingschan
 * 
 */

public class TagParseFactory {
	private static Logger log = Logger.getLogger(TagParseFactory.class);
	/**
	 * executeParse
	 * @param tag
	 * @param root
	 * @throws Exception
	 */
	public static String executeParse(RootTag tag,PageContext context) throws Exception {
		long executeDate = System.currentTimeMillis();
		String html = null;
		TagMetaData sp = tag.getClass().getAnnotation(TagMetaData.class);
		JeasyTagFormat format = (JeasyTagFormat) Class.forName(sp.parseClass()).newInstance();		
		html = format.format(tag, context);
		long finishDate=System.currentTimeMillis();
		log.info(String.format("tag :%s parse time %s", tag.getClass(),DateUtil.runtimeDifference(finishDate-executeDate)));
		return html;
	}

	
}
